﻿/*
 * Subject：Dapper的基本操作帮助类
 * Date：2023/01/10
 * Author：Max
 * Content：包含Dapper的CRUD的操作
 * Modify：
 *      Date：2023/01/18
 *      Content：添加了一个xxxx方法
 * 
 * **/

using Dapper;
using MySql.Data.MySqlClient;
using System;
using System.Collections.Generic;
using System.Data;
using System.Data.SqlClient;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Max.PH6_2006A.LowCode.DataAccess
{
    /*
     * Dapper是基本IDbConnection
     * 
     * **/
    public class DapperHelper
    {
        public IDbConnection DbConnection { get; }
        public DapperHelper(string type,string connection)
        {
            DbConnection = DapperFactory.Instance(type, connection);
        }

        #region 执行SQL，受影响行数



        ////插入（添加）
        //public int Insert(string sql,object param) 
        //{
        //   int result =  DbConnection.Execute(sql, param);
        //    return result;
        //}

        ////删除
        //public int Delete(string sql,object param)
        //{
        //    int result = DbConnection.Execute(sql, param);
        //    return result;
        //}

        ////修改
        //public int Update(string sql, object param)
        //{
        //    int result = DbConnection.Execute(sql, param);
        //    return result;
        //}

        #endregion

        #region 直接用IDbContext对象，不在这封装

        ////用一个方法，替代上面的三个操作
        ///// <summary>
        ///// 执行SqL语句，返回受影响行数
        ///// </summary>
        ///// <param name="sql"></param>
        ///// <param name="param"></param>
        ///// <returns></returns>
        //public int Execute(string sql, object param, IDbTransaction? transcation = null, int? commandTimeut = null, CommandType? commandType = null)
        //{
        //    int result = DbConnection.Execute(sql, param,transcation,commandTimeut,commandType);
        //    return result;
        //}
        //public async Task<int> ExecuteAsync(string sql, object param, IDbTransaction? transcation = null, int? commandTimeut = null, CommandType? commandType = null)
        //{
        //    int result = await DbConnection.ExecuteAsync(sql, param, transcation, commandTimeut, commandType);
        //    return result;
        //}
        //public IEnumerable<dynamic> Query(string sql,object param = null, IDbTransaction? transcation = null,bool buffered = true,  int? commandTimeut = null, CommandType? commandType = null) 
        //{
        //    IEnumerable<dynamic> result =  DbConnection.Query(sql,param,transcation,buffered, commandTimeut,commandType);
        //    return result;
        //}

        #endregion

        public  void Test()
        {
            DbConnection.Open();

            

            int a =DbConnection.Execute("",null,null,null,CommandType.StoredProcedure);
            IEnumerable<dynamic> data =  DbConnection.Query("", null, null, true, null, null);
        }
    }




}
